﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Async;
using CommonHelper.Model;
using CommonHelper.Model.Qy;
using CommonHelper.Server.Qy;

namespace WeiXinGeneralApi.Controllers.Qy
{
    public class DepartmentController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult List(string accessToken)
        {
            GetDepartmentList deptList = null;
            if (!string.IsNullOrWhiteSpace(accessToken))
            {
                deptList = DepartmentService.GetDepartmentList(accessToken,"1");
            }
            return View(deptList);
        }

        //
        // GET: /Department/
        [HttpGet]
        public ActionResult Add()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Add(string accessToken, string id, string name, string order, string parentId)
        {
            var dept = new DepartmentResult
            {
                id = id,
                name = name,
                order = order,
                parentid = parentId
            };
            var result = DepartmentService.CreateDepartMent(accessToken, dept);
            return Json(result.errmsg);
        }

        [HttpGet]
        public ActionResult Update(string id)
        {
            return View();
        }

        [HttpPost]
        public ActionResult Update()
        {
            return Json("");
        }

        [HttpPost]
        public ActionResult Delete(string id)
        {
            var accesstoken = "aXn4uW-Q4an-LOdPS2Abg766g-GFbV1ztQfK5tLCmFV1jQBMX7otjd4iwEJouQkm1VdLfAslOybLjsCUVzXtWA";
            var res = DepartmentService.DeletePartment(accesstoken, id);
            return Json(res.errmsg);
        }
    }
}
